home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1996 #6 / Amiga Plus CD - 1996 - No. 06.iso / pd / programmierung / proasm / routines / string.r < prev    next >
Text File  |  1995-04-05  |  7KB  |  346 lines

  1.  
  2. ;---;  string.r  ;-------------------------------------------------------------
  3. *
  4. *    ****    string support routines    ****
  5. *
  6. *    Author        Daniel Weber
  7. *    Version        1.10
  8. *    Last Revision    23.02.95
  9. *    Identifier    str_defined
  10. *       Prefix        str_    (String)
  11. *                 ¯¯¯
  12. *    Functions    StrCmp, StrCmpSpc, ARexxStrCmp, GetStrLen, StrLen,
  13. *            StrCopy, StrNCopy, StrNCmp, SStrCopy, SStrNCopy
  14. *
  15. ;------------------------------------------------------------------------------
  16.  
  17. ;------------------
  18.     ifnd    str_defined
  19. str_defined    SET    1
  20.  
  21. ;------------------
  22. str_oldbase    equ __BASE
  23.     base    str_base
  24. str_base:
  25.  
  26. ;------------------
  27.     opt    sto,o+,ow-,q+,qw-        ;all optimisations on
  28.  
  29. ;------------------
  30.  
  31.  
  32. ;------------------------------------------------------------------------------
  33. *
  34. * StrCmp    Compare Zero Ending Strings (case independant)
  35. *
  36. * INPUT:    A0    first string
  37. *        A1    second string
  38. *
  39. * RESULT:    D0.l    0: equal    -: position of first difference  (CCR)
  40. *
  41. ;------------------------------------------------------------------------------
  42.     IFD    xxx_StrCmp
  43. xxx_str_tablist    SET    1
  44.  
  45. StrCmp:
  46.     movem.l    d1-d2/a0-a1/a5,-(a7)
  47.     moveq    #0,d0
  48.     moveq    #0,d1
  49.     moveq    #0,d2
  50.     lea    str_base(pc),a5
  51. .loop:    addq.l    #1,d0
  52.     move.b    (a0)+,d1
  53.     beq.s    .ok
  54.     move.b    (a1)+,d2
  55.     beq.s    .false
  56.     move.b    str_tablist(a5,d1.w),d1        ;make it case independant
  57.     cmp.b    str_tablist(a5,d2.w),d1
  58.     beq.s    .loop
  59. .false:    tst.l    d0
  60.     movem.l    (a7)+,d1-d2/a0-a1/a5
  61.     rts
  62.  
  63. .ok:    tst.b    (a1)
  64.     bne.s    .false
  65. .right:    moveq    #0,d0                ;set return value
  66.     bra.s    .false
  67.  
  68.     ENDC
  69.  
  70. ;------------------------------------------------------------------------------
  71. *
  72. * StrNCmp    Compare Zero Ending Strings (case independant), with length N
  73. *
  74. * INPUT:    D0    max. length for strings
  75. *            A0    first string
  76. *            A1    second string
  77. *
  78. * RESULT:    D0    0: equal    -: position of first difference  (CCR)
  79. *
  80. ;------------------------------------------------------------------------------
  81.     IFD    xxx_StrNCmp
  82. xxx_str_tablist    SET    1
  83.  
  84. StrNCmp:
  85.     movem.l    d1-d3/a0-a1/a5,-(a7)
  86.     moveq    #0,d3
  87.     moveq    #0,d1
  88.     moveq    #0,d2
  89.     exg    d3,d0
  90.     lea    str_base(pc),a5
  91. .loop:    addq.l    #1,d0
  92.     subq.l    #1,d3
  93.     bmi.s    .right
  94.     move.b    (a0)+,d1
  95.     beq.s    .ok
  96.     move.b    (a1)+,d2
  97.     beq.s    .false
  98.     move.b    str_tablist(a5,d1.w),d1        ;make it case independant
  99.     cmp.b    str_tablist(a5,d2.w),d1
  100.     beq.s    .loop
  101. .false:    tst.l    d0
  102.     movem.l    (a7)+,d1-d3/a0-a1/a5
  103.     rts
  104.  
  105. .ok:    tst.b    (a1)
  106.     bne.s    .false
  107. .right:    moveq    #0,d0                ;set return value
  108.     bra.s    .false
  109.  
  110.     ENDC
  111.  
  112. ;------------------------------------------------------------------------------
  113. *
  114. * StrCmpSpc    Compare Space Ending Strings (case independant)
  115. *
  116. * INPUT:    A0    first string
  117. *        A1    second string
  118. *
  119. * RESULT:    D0    0: equal    -: position of first difference
  120. *
  121. ;------------------------------------------------------------------------------
  122.     IFD    xxx_StrCmpSpc
  123. xxx_str_tablist    SET    1
  124.  
  125. StrCmpSpc:
  126.     movem.l    d1-d2/a0-a1/a5,-(a7)
  127.     moveq    #0,d0
  128.     moveq    #0,d1
  129.     moveq    #0,d2
  130.     lea    str_base(pc),a5
  131. .loop:    addq.l    #1,d0
  132.     move.b    (a0)+,d1
  133.     move.b    (a1)+,d2
  134.     move.b    str_tablist(a5,d1.w),d1        ;make it case independant
  135.     cmp.b    str_tablist(a5,d2.w),d1
  136.     bne.s    .false
  137.     cmp.b    #" ",d1
  138.     bne.s    .loop
  139. .right:    moveq    #0,d0                ;set return value
  140. .false:    movem.l    (a7)+,d1-d2/a0-a1/a5
  141.     rts
  142.  
  143.     ENDC
  144.  
  145. ;------------------------------------------------------------------------------
  146. *
  147. * ARexxStrCmp    Compare ARexx String (case independant)
  148. *
  149. * INPUT:    A0    source string    (zero ending)
  150. *        A1    Argument string  (space or zero ending)
  151. *
  152. * RESULT:    D0    0: equal    -: position of first difference
  153. *
  154. ;------------------------------------------------------------------------------
  155.     IFD    xxx_ARexxStrCmp
  156. xxx_str_tablist    SET    1
  157.  
  158. ARexxStrCmp:
  159.     movem.l    d1-d3/a0-a1/a5,-(a7)
  160.     moveq    #0,d0
  161.     moveq    #0,d1
  162.     moveq    #0,d2
  163.     moveq    #" ",d3
  164.     lea    str_base(pc),a5
  165. .loop:    addq.l    #1,d0
  166.     move.b    (a0)+,d1
  167.     move.b    (a1)+,d2
  168.     cmp.b    d3,d2
  169.     beq.s    .ok
  170.     move.b    str_tablist(a5,d1.w),d1        ;make it case independant
  171.     cmp.b    str_tablist(a5,d2.w),d1
  172.     bne.s    .false
  173.     tst.b    d1                ;EOsource string?
  174.     bne.s    .loop
  175. .right:    moveq    #0,d0                ;set return value
  176. .false:    movem.l    (a7)+,d1-d3/a0-a1/a5
  177.     rts
  178.  
  179. .ok:    tst.b    d1                ;also EOsource???
  180.     beq.s    .right
  181.     bra.s    .false                ;no! -> error
  182.  
  183.     ENDC
  184.  
  185.  
  186. ;------------------------------------------------------------------------------
  187. *
  188. * GetStrLen    Get length of a given zero ended string
  189. * StrLen    varargs stub for GetStrLen
  190. *
  191. * INPUT:    A0    string
  192. *
  193. * RESULT:    D0    string length (excluding the zero byte)
  194. *
  195. ;------------------------------------------------------------------------------
  196.     IFD    xxx_StrLen
  197.     NEED_    GetStrLen
  198. StrLen:
  199.     ENDC
  200.  
  201.  
  202.     IFD    xxx_GetStrLen
  203. GetStrLen:
  204.     move.l    a0,-(a7)
  205.     moveq    #-1,d0
  206. \loop:    addq.l    #1,d0
  207.     tst.b    (a0)+
  208.     bne.s    \loop
  209. 2$:    move.l    (a7)+,a0
  210.     rts
  211.  
  212.     ENDC
  213.  
  214.  
  215. ;------------------------------------------------------------------------------
  216. *
  217. * StrCopy    Copy zero-terminated string
  218. *
  219. * INPUT:    A0    source string
  220. *        A1    target buffer
  221. *
  222. * RESULT:    registers A0-A1 affected!
  223. *
  224. ;------------------------------------------------------------------------------
  225.     IFD    xxx_StrCopy
  226. StrCopy:
  227. 0$:    move.b    (a0)+,(a1)+
  228.     bne.s    0$
  229.     rts
  230.  
  231.     ENDC
  232.  
  233.  
  234.  
  235. ;------------------------------------------------------------------------------
  236. *
  237. * StrNCopy    Copy zero-terminated string with a max. length of N
  238. *
  239. * INPUT:    D0    max number or bytes (word).
  240. *        A0    source string
  241. *        A1    target buffer
  242. *
  243. * RESULT:    registers D0/A0-A1 affected!
  244. *
  245. ;------------------------------------------------------------------------------
  246.     IFD    xxx_StrNCopy
  247. StrNCopy:
  248.     bra.s    1$
  249. 0$:    move.b    (a0)+,(a1)+
  250. 1$:    dbeq    d0,0$
  251.     rts
  252.     ENDC
  253.  
  254.  
  255. ;------------------------------------------------------------------------------
  256. *
  257. * SStrCopy    Copy zero-terminated string SAVELY
  258. *
  259. * INPUT:    A0    source string
  260. *        A1    target buffer
  261. *
  262. * RESULT:    none
  263. *
  264. ;------------------------------------------------------------------------------
  265.     IFD    xxx_SStrCopy
  266. SStrCopy:
  267.     movem.l    a0/a1,-(a7)
  268. 0$:    move.b    (a0)+,(a1)+
  269.     bne.s    0$
  270.     movem.l    (a7)+,a0/a1
  271.     rts
  272.  
  273.     ENDC
  274.  
  275.  
  276.  
  277. ;------------------------------------------------------------------------------
  278. *
  279. * SStrNCopy    Copy zero-terminated string with a max. length of N SAVELY
  280. *
  281. * INPUT:    D0    max number or bytes (word).
  282. *        A0    source string
  283. *        A1    target buffer
  284. *
  285. * RESULT:    none
  286. *
  287. ;------------------------------------------------------------------------------
  288.     IFD    xxx_SStrNCopy
  289. SStrNCopy:
  290.     movem.l    a0/a1,-(a7)
  291.     bra.s    1$
  292. 0$:    move.b    (a0)+,(a1)+
  293. 1$:    dbeq    d0,0$
  294.     movem.l    (a7)+,a0/a1
  295.     rts
  296.  
  297.     ENDC
  298.  
  299.  
  300. ;------------------------------------------------------------------------------
  301. *
  302. * Data area (easier access using a base register)
  303. *
  304. ;------------------------------------------------------------------------------
  305.     IFD    xxx_str_tablist
  306.  
  307. str_tablist:
  308.     dc.b    0,1,2,3,4,5,6,7,8,9,$a,$b,$c,$d,$e,$f
  309.     dc.b    $10,$11,$12,$13,$14,$15,$16,$17
  310.     dc.b    $18,$19,$1a,$1b,$1c,$1d,$1e,$1f
  311.     dc.b    " !",$22,"#$%&'()*+,-./"
  312.     dc.b    "0123456789:;<=>?"
  313.     dc.b    "@ABCDEFGHIJKLMNO"
  314.     dc.b    "PQRSTUVWXYZ[\]^_"
  315.     dc.b    "`ABCDEFGHIJKLMNO"
  316.     dc.b    "PQRSTUVWXYZ{|}~",$7F
  317.     dc.b    $80,$81,$82,$83,$84,$85,$86,$87
  318.     dc.b    $88,$89,$8a,$8b,$8c,$8d,$8e,$8f
  319.     dc.b    $90,$91,$92,$93,$94,$95,$96,$97
  320.     dc.b    $98,$99,$9a,$9b,$9c,$9d,$9e,$9f
  321.     dc.b    $a0,$a1,$a2,$a3,$a4,$a5,$a6,$a7
  322.     dc.b    $a8,$a9,$aa,$ab,$ac,$ad,$ae,$af
  323.     dc.b    $b0,$b1,$b2,$b3,$b4,$b5,$b6,$b7
  324.     dc.b    $b8,$b9,$ba,$bb,$bc,$bd,$be,$bf
  325.     dc.b    $c0,$c1,$c2,$c3,$c4,$c5,$c6,$c7
  326.     dc.b    $c8,$c9,$ca,$cb,$cc,$cd,$ce,$cf
  327.     dc.b    $d0,$d1,$d2,$d3,$d4,$d5,$d6,$d7
  328.     dc.b    $d8,$d9,$da,$db,$dc,$dd,$de,$df
  329.     dc.b    $e0,$e1,$e2,$e3,$e4,$e5,$e6,$e7
  330.     dc.b    $e8,$e9,$ea,$eb,$ec,$ed,$ee,$ef
  331.     dc.b    $f0,$f1,$f2,$f3,$f4,$f5,$f6,$f7
  332.     dc.b    $f8,$f9,$fa,$fb,$fc,$fd,$fe,$ff
  333.  
  334.     ENDC
  335. ;--------------------------------------------------------------------
  336.     base    str_oldbase
  337.  
  338. ;------------------
  339.     opt    rcl
  340.  
  341. ;------------------
  342.     endif
  343.  
  344.  end
  345.  
  346.